/*
 * Copyright (C) 2012 SeekDeepWithin.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.seekdeepwithin.Data;

import java.util.*;

/**
 * User: Jonathan Montiverdi Date: Oct 3, 2012
 * Represents a book/database.
 */
public class Book extends BaseDbObject
{
   private Date m_LastModified;
   private String m_Author;
   private String m_Info;
   private String m_Date;
   private String m_Subtitle;
   private String m_AmazonId;
   private String m_Abbreviation;
   private boolean m_HasSubBooks;
   private boolean m_HasChapters;
   private boolean m_IsSubBook;
   private List<Source> m_Sources = null;
   private List<BaseDbObject> m_Translators = null;
   private List<SubBook> m_SubBooks = null;

   /**
    * Initializes a new book, copying data from the given book.
    * @param copyBook Book to copy data from.
    */
   public Book (Book copyBook)
   {
      super (copyBook.getId (), copyBook.getTitle ());
      this.copyBook (copyBook);
   }

   /**
    * Initializes a new book at the given path.
    * @param title The title of the book.
    * @param id The ID of the book.
    */
   public Book (String title, int id)
   {
      super (id, title);
   }

   /**
    * Gets the title (name) of the book.
    * @return Name of the book.
    */
   public String getTitle ()
   {
      return this.getName ();
   }

   /**
    * Gets the author of the book.
    * @return Author of the book.
    */
   public String getAuthor ()
   {
      return this.m_Author;
   }

   /**
    * Sets the author of the book.
    * @param author The author of the book.
    */
   public void setAuthor (String author)
   {
      this.m_Author = author;
   }

   /**
    * Gets the abbreviation of the book.
    * @return Abbreviation of the book.
    */
   public String getAbbreviation ()
   {
      return this.m_Abbreviation;
   }

   /**
    * Sets the abbreviation of the book.
    * @param abbreviation The abbreviation of the book.
    */
   public void setAbbreviation (String abbreviation)
   {
      this.m_Abbreviation = abbreviation;
   }

   /**
    * Gets the amazon ID of the book.
    * @return Amazon ID of the book.
    */
   public String getAmazonId ()
   {
      return this.m_AmazonId;
   }

   /**
    * Sets the amazon ID of the book.
    * @param amazonId The amazon id of the book.
    */
   public void setAmazonId (String amazonId)
   {
      this.m_AmazonId = amazonId;
   }

   /**
    * Gets information about the book.
    * @return Information about the book.
    */
   public String getInfo ()
   {
      return this.m_Info;
   }

   /**
    * Sets the information of the book.
    * @param info The information of the book.
    */
   public void setInfo (String info)
   {
      this.m_Info = info;
   }

   /**
    * Gets date of the book.
    * @return Date of the book.
    */
   public String getDate ()
   {
      return this.m_Date;
   }

   /**
    * Sets the date of the book.
    * @param date The date of the book.
    */
   public void setDate (String date)
   {
      this.m_Date = date;
   }

   /**
    * Gets the books last modified date.
    * @return Books last modified date.
    */
   public Date getLastModified ()
   {
      return this.m_LastModified;
   }

   /**
    * Sets of this book has sub books or not.
    * @param hasSubBooks True if book has sub books, otherwise false.
    */
   public void setHasSubBooks (boolean hasSubBooks)
   {
      this.m_HasChapters = hasSubBooks;
   }

   /**
    * Gets if the book has any sub books or not.
    * @return True if the book has sub books, otherwise false.
    */
   public boolean HasSubBooks ()
   {
      return this.m_HasSubBooks;
   }

   /**
    * Sets if this book has chapters or not.
    * @param hasChapters True if book has chapters, otherwise false.
    */
   public void setHasChapters (boolean hasChapters)
   {
      this.m_HasChapters = hasChapters;
   }

   /**
    * Gets if the book has chapters or not.
    * @return True if the book has chapters, otherwise false.
    */
   public boolean HasChapters ()
   {
      return this.m_HasChapters;
   }

   /**
    * Sets if this book is a sub book or not.
    * @param hasChapters True if book is a sub book, otherwise false.
    */
   public void setIsSubBook (boolean isSubBook)
   {
      this.m_IsSubBook = isSubBook;
   }

   /**
    * Gets if the book is a sub book or not.
    * @return True if the book is a sub book, otherwise false.
    */
   public boolean getIsSubBook ()
   {
      return this.m_IsSubBook;
   }

   /**
    * Gets the sub title of the book, if any.
    * @return The books subtitle.
    */
   public String getSubTitle ()
   {
      return this.m_Subtitle;
   }

   /**
    * Sets the sub title of the book.
    * @param subTitle The books subtitle.
    */
   public void setSubTitle (String subTitle)
   {
      this.m_Subtitle = subTitle;
   }

   /**
    * Gets the list of sources for the book.
    * @return List of sources.
    */
   public List<Source> getSources ()
   {
      if (this.m_Sources == null) {
         this.m_Sources = new ArrayList<> ();
      }
      return this.m_Sources;
   }

   /**
    * Adds a new source for the book.
    * @param sourceId ID of source.
    * @param source Source.
    * @param sourceNameId ID of source's name.
    * @param sourceName Name of source.
    */
   public void addSource (int sourceId, String source, int sourceNameId, String sourceName)
   {
      this.getSources ().add (new Source (sourceId, source, sourceNameId, sourceName));
   }

   /**
    * Gets the list of translators for the book.
    * @return List of translators.
    */
   public List<BaseDbObject> getTranslators ()
   {
      if (this.m_Translators == null) {
         this.m_Translators = new ArrayList<> ();
      }
      return this.m_Translators;
   }

   /**
    * Adds a translator for the book.
    * @param translatorId ID of the translator.
    * @param translator Translator.
    */
   public void addTranslator (int translatorId, String translator)
   {
      this.getTranslators ().add (new BaseDbObject (translatorId, translator));
   }

   /**
    * Gets the sub book list.
    * @return The list of sub books.
    */
   public List<SubBook> getSubBooks ()
   {
      if (this.m_SubBooks == null) {
         this.m_SubBooks = new ArrayList<> ();
      }
      return this.m_SubBooks;
   }

   /**
    * Copies the given book into this object.
    * @param bookToCopy Book to copy from.
    */
   private void copyBook (Book bookToCopy)
   {
      this.setAbbreviation (bookToCopy.getAbbreviation ());
      this.setAmazonId (bookToCopy.getAmazonId ());
      this.setAuthor (bookToCopy.getAuthor ());
      this.setDate (bookToCopy.getDate ());
      this.setHasChapters (bookToCopy.HasChapters ());
      this.setHasSubBooks (bookToCopy.HasSubBooks ());
      this.setInfo (bookToCopy.getInfo ());
      this.setIsSubBook (bookToCopy.getIsSubBook ());
      this.setSubTitle (bookToCopy.getSubTitle ());
   }
}
